<template>
    <div class="markModel">
        <el-row :gutter="24">
            <el-col :span="14">
                <el-form :inline="true" class="demo-form-inline">
                    <el-form-item label="公开（公告）号">


                        <el-input v-model="formInline.gk_gg_h" placeholder="搜索"></el-input>
                    </el-form-item>
                    <el-form-item label="专利名称">

                        <el-input v-model="formInline.bt_zw_" placeholder="搜索"></el-input>
                    </el-form-item>

                    <el-form-item>
                        <el-button @click="resetForm()">重置</el-button>
                        <el-button type="primary" @click="onSubmit">查询</el-button>
                    </el-form-item>
                    <el-form-item>

                        <el-button type="primary" @click="addModel()">新增</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
        <el-row :gutter="24">
            <el-col :span="24">
                <el-table :data="tableData" border style="width: 100%" align="center">
                    <el-table-column type="index" width="50" center>
                    </el-table-column>
                    <el-table-column prop="gk_gg_h" label="公开（公告）号" width="180">
                    </el-table-column>
                    <el-table-column prop="bt_zw_" label="专利名称" >
                    </el-table-column>
                    <el-table-column prop="zhaiyao" label="摘要">
                    </el-table-column>
                    <el-table-column fixed="right" label="推荐企业" width="100">
                        <template slot-scope="scope">
                            <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>


                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>
        <div style="text-align: right; margin-top: 20px;">

            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                :page-sizes="[10, 20, 30, 40, 50, 100]" :page-size="pageSize" layout="total, prev, pager, next, sizes"
                :total="total">
            </el-pagination>
        </div>
        <el-dialog title="新增" :visible.sync="dialogFormVisible">
            <el-form :model="form" ref="form" label-position="top">
                <el-row :gutter="24">
                    <el-col :span="24">

                        <el-form-item label="请在输入公开（公告）号之后，在输入框中按键盘上的Enter（回车）">
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="24">
                    <el-col :span="12">
                        <el-form-item label="专利名称" :label-width="formLabelWidth">
                            <el-input v-model="form.bt_zw_" autocomplete="off" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="公开（公告）号" :label-width="formLabelWidth">
                            <el-input v-model="form.gk_gg_h" autocomplete="off" @change="inputChange"></el-input>
                        </el-form-item>

                    </el-col>
                </el-row>

                <el-row :gutter="24">
                    <el-col :span="24">
                        <el-form-item label="摘要" :label-width="formLabelWidth">
                            <el-input type="textarea" v-model="form.zhaiyao" autosize :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="addRow">提交</el-button>
            </div>
        </el-dialog>

        <!-- 查看 -->
        <el-dialog :span="24" :visible.sync="rowVisible" width="70%">
            <el-row :gutter="24">
                <el-col :span="2">
                    <el-button @click="addFirmShow = true" type="primary" size="small"
                        style="margin-bottom: 30px;">新增企业</el-button>
                </el-col>
            </el-row>
            <el-descriptions class="margin-top" :title="rowItem.bt_zw_" :column="2">
                <el-descriptions-item label="公开（公告）号"> &nbsp;&nbsp; {{ rowItem.gk_gg_h }}</el-descriptions-item>
                <el-descriptions-item label="专利名称">&nbsp;&nbsp;{{ rowItem.bt_zw_ }}</el-descriptions-item>


            </el-descriptions>
            <div class="rowBox_bottom">
                <div style="width: 48%;text-align: left;">
                    <p>推荐公司</p>
                    <el-table :data="tuijianList" border>
                        <el-table-column property="gongsi" label="公司名称"></el-table-column>

                    </el-table>
                </div>

                <div style="width: 48%;text-align: left;">
                    <p>公司列表</p>
                    <el-table :data="qiyeList" border>
                        <el-table-column property="gsmc" label="公司名称"></el-table-column>
                    </el-table>

                </div>



            </div>
        </el-dialog>


        <!-- 新增企业 -->
        <el-dialog :span="24" title="新增企业" :visible.sync="addFirmShow">
            <el-form :model="firm" ref="firm" label-position="top">

                <el-row :gutter="24">
                    <el-col :span="12">
                        <el-form-item label="公司名称" :label-width="formLabelWidth">
                            <el-input v-model="firm.gsmc"></el-input>
                        </el-form-item>

                    </el-col>
                </el-row>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="addFirmShow = false">取 消</el-button>
                <el-button type="primary" @click="addFirm">提交</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import Cookies from "js-cookie";

export default {
    data() {
        return {
            userInfo:{},
            tableData: [],
            currentPage: 1,
            pageSize: 50,
            total: 0,
            dialogFormVisible: false,
            form: {
                gk_gg_h: '',
               
                zhaiyao: '',
              
                bt_zw_: '',
                ssdw: '首都医科大学附属北京儿童医院',

            },
            formLabelWidth: '100px',
            rowsItem: {},
            formInline: {
                bt_zw_: '',
                gk_gg_h: ''
            },
            visible: false,
            rowItem: {},
            rowVisible: false,
            tuijianList: [],
            qiyeList: [],
            addFirmShow: false,
            firm: {
                gsmc: ''
            }
        }
    },
    created() {

    },
    mounted() {
        this.getCookie();
        this.getFilterRows()
    },
    methods: {
        getCookie() {
            this.userInfo = JSON.parse(Cookies.get("userInfo"));
        },

        //新增
        addModel(formName) {
            this.form.gk_gg_h = ''
          
            this.form.zhaiyao = ''
            this.form.bt_zw_ = ''
        
            this.dialogFormVisible = true
            console.log(this.form)
        },

        //输入公开（公告）号
        inputChange() {
            console.log(this.form.gk_gg_h)
            var param = {
                "appKey": "c4d42996f1b29c98",
                "sign": "MGJjY2VmMGQwYjIzYzM3OTBjYmYyODk0ODJjOGQ0ZmY1Y2MzZTRlZDNkMmIyYzM1NTRjZDMxYTIwMzg3ODIzMw==",
                "worksheetId": "64f697fbe13132adf644a4f9",
                "viewId": "",
                "pageSize": this.pageSize,
                "pageIndex": this.currentPage,
                "sortId": "",
                "isAsc": "true",
                "filters": [
                    {
                        "controlId": "gk_gg_h",
                        "dataType": 2,
                        "spliceType": 1,
                        "filterType": 1,
                        "value": this.form.gk_gg_h
                    },

                ]
            }
            this.$apiFun.getFilterRows(param).then((res) => {
                //根据后端返回数据进行data的逻辑处理
                console.log(res)
                // this.total = res.data.total
                // this.tableData = res.data.rows
                if (res.data.rows.length > 0) {
                    var rows = res.data.rows[0]
                    
                    this.form.zhaiyao = rows.zy_zw_
                    this.form.bt_zw_ = rows.bt_zw_
                    this.form.ssdw = this.userInfo.danwei
                   

                    // item = res.data.rows[0]
                    // this.predict(res.data.rows[0])
                }


            })
        },

        //获取列表
        getFilterRows() {
            var param = {
                "appKey": "c4d42996f1b29c98",
                "sign": "MGJjY2VmMGQwYjIzYzM3OTBjYmYyODk0ODJjOGQ0ZmY1Y2MzZTRlZDNkMmIyYzM1NTRjZDMxYTIwMzg3ODIzMw==",
                "worksheetId": "64a65e9edc625ae51a8dc976",
                "viewId": "",
                "pageSize": this.pageSize,
                "pageIndex": this.currentPage,
                "sortId": "",
                "isAsc": "true",
                "filters": [
                    {
                        "controlId": "bt_zw_",
                        "dataType": 2,
                        "spliceType": 1,
                        "filterType": 1,
                        "value": this.formInline.bt_zw_
                    },
                    {
                        "controlId": "gk_gg_h",
                        "dataType": 2,
                        "spliceType": 1,
                        "filterType": 1,
                        "value": this.formInline.gk_gg_h
                    }
                    ,
                    {
                        "controlId": "ssdw",
                        "dataType": 2,
                        "spliceType": 1,
                        "filterType": 1,
                        "value": this.userInfo.danwei
                    }
                ]
            }
            this.$apiFun.getFilterRows(param).then((res) => {
                //根据后端返回数据进行data的逻辑处理
                console.log(res)
                this.total = res.data.total
                this.tableData = res.data.rows
            })
        },

        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.getFilterRows()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.getFilterRows()
        },



        //模型接口
        predict(item) {
            console.log(item)
            var param = {
                "zlyxx": item.zlyxx,
                "sscs": item.sscs,
                "zycs": item.zycs,
                "flsj": item.flsj,
                "jdtzgs": item.jdtzgs,
                "kztzgs": item.kztzgs,
                "ipc": item.ipc,
                "sqrsl": item.sqrsl,
                "fmrsl": item.fmrsl,
                "xkcs": item.xkcs,
                "zrcs": item.zrcs,
                "hgba": item.hgba,
                "qlyqsl": item.qlyqsl,
                "dlqlyqsl": item.dlqlyqsl,
                "csqlyqsl": item.csqlyqsl,
                "wxys": item.wxys,
                "sqzs": item.sqzs,
                "zllx": item.zllx,
                // "shenqingri": '2006-05-31',
                "shenqingri": item.shenqingri,
                "sqggr": item.sqggr,
                "shixiaori": item.shixiaori,
                "tzgj_dq": item.tzgj_dq,
                "sqrlx": item.sqrlx,
                "sslx": item.sslx,
                "jiangxiang": item.jiangxiang,
                "gk_gg_h": item.gk_gg_h
            }
            this.$apiFun.predict(param).then((res) => {
                //根据后端返回数据进行data的逻辑处理
                console.log(res)
                this.form.fenji = res.prediction
                this.form.bzzl = res.bzzl
                this.form.hgba = res.hgba
                this.form.hjqk = res.hjqk
                this.form.qqqk = res.qqqk
                this.form.wxqk = res.wxqk
                this.form.xkqk = res.xkqk
                this.form.zrqk = res.zrqk
                this.form.zzfj = res.prediction
            })
        },

        //点击确认之后执行：新增记录
        addRow() {
            // this.dialogFormVisible = false
            if (this.form.gk_gg_h == '') {
                this.$message({
                    message: '请输入公开（公告）号',
                    type: 'warning'
                });
                return
            }
            var param = {
                "bt_zw_":  this.form.bt_zw_,
                "zhaiyao":this.form.zhaiyao,
                "gk_gg_h": this.form.gk_gg_h,
                "ssdw": this.form.ssdw
            }
            this.$apiFun.simliary(param).then((res) => {
                //根据后端返回数据进行data的逻辑处理
                console.log(res)
                this.dialogFormVisible = false
                this.getFilterRows()
            })
        },
        //重置
        resetForm(formName) {
            this.formInline.bt_zw_ = ''
            this.formInline.gk_gg_h = ''
           
            this.getFilterRows()
        },
        //提交
        onSubmit() {
            console.log('submit!');
            this.getFilterRows()
        },
       

        //查看
        handleClick(row) {
            this.rowItem = row
            this.rowVisible = true
            this.tuijian(row.rowid)
            this.getQiyeList(row.rowid)
        },
        //推荐企业
        tuijian(rowid) {
            var param = {
                "appKey": "c4d42996f1b29c98",
                "sign": "MGJjY2VmMGQwYjIzYzM3OTBjYmYyODk0ODJjOGQ0ZmY1Y2MzZTRlZDNkMmIyYzM1NTRjZDMxYTIwMzg3ODIzMw==",
                "worksheetId": "64a65e9edc625ae51a8dc976",
                "rowId": rowid,
                "controlId": "qxzcxxpplb"
            }
            this.$apiFun.getRowRelations(param).then((res) => {
                this.tuijianList = res.data.rows
            })

        },
        getQiyeList(rowid) {
            var param = {
                "appKey": "c4d42996f1b29c98",
                "sign": "MGJjY2VmMGQwYjIzYzM3OTBjYmYyODk0ODJjOGQ0ZmY1Y2MzZTRlZDNkMmIyYzM1NTRjZDMxYTIwMzg3ODIzMw==",
                "worksheetId": "64a65e9edc625ae51a8dc976",
                "rowId": rowid,
                "controlId": "qybmd"
            }
            this.$apiFun.getRowRelations(param).then((res) => {
                this.qiyeList = res.data.rows
            })
        },


        //addFirm
        addFirm() {
            var param = {
                "appKey": "c4d42996f1b29c98",
                "sign": "MGJjY2VmMGQwYjIzYzM3OTBjYmYyODk0ODJjOGQ0ZmY1Y2MzZTRlZDNkMmIyYzM1NTRjZDMxYTIwMzg3ODIzMw==",
                "worksheetId": "qybmd",
                "controls": [
                    {
                        "controlId": "gsmc",
                        "value": this.firm.gsmc
                    },
                    {
                        "controlId": "qyzlyqyzcxxppjg_cs_",
                        "value": this.rowItem.rowid
                    }
                ]
            }
            this.$apiFun.addRow(param).then((res) => {
                this.tuijian(this.rowItem.rowid)
                this.getQiyeList(this.rowItem.rowid)
                this.addFirmShow = false
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.markModel {
    background-color: #fff;
    padding: 15px;
}

td {
    // padding-bottom: 50px !important;
}

.el-form-item {
    text-align: left;
}

.rowBox_bottom {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
</style>